package com.joysuch.wwyt.mh.service.impl;

import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.joysuch.wwyt.bp.entity.BpDepart;
import com.joysuch.wwyt.bp.mapper.InspectExceptionAlarmMesageMapper;
import com.joysuch.wwyt.bp.repository.BpDepartDao;
import com.joysuch.wwyt.core.entity.BaseConfig;
import com.joysuch.wwyt.core.enums.BaseConfigCodes;
import com.joysuch.wwyt.core.repository.BaseConfigDao;
import com.joysuch.wwyt.core.repository.BaseUserDao;
import com.joysuch.wwyt.core.support.Context;
import com.joysuch.wwyt.mh.bean.MhGradingAlarmBean;
import com.joysuch.wwyt.mh.dto.MhGradingAlarmDto;
import com.joysuch.wwyt.mh.entity.MhGradingAlarm;
import com.joysuch.wwyt.mh.mapper.MhGradingAlarmMapper;
import com.joysuch.wwyt.mh.repository.MhAlarmMessageDao;
import com.joysuch.wwyt.mh.service.MhGradingAlarmService;
import com.joysuch.wwyt.workflow.repository.WorkFlowTaskDao;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;


@Service
@Transactional
@Slf4j
public class MhGradingAlarmServiceImpl implements MhGradingAlarmService {

    @Autowired
    private MhGradingAlarmMapper mhGradingAlarmMapper;
    @Autowired
    private BaseUserDao baseUserDao;
    @Autowired
    private BaseConfigDao baseConfigDao;
    @Autowired
    private MhAlarmMessageDao mhAlarmMessageDao;
    @Autowired
    private InspectExceptionAlarmMesageMapper inspectExceptionAlarmMesageMapper;
    @Autowired
    private WorkFlowTaskDao workFlowTaskDao;
    @Autowired
    private BpDepartDao bpDepartDao;

    @Override
    public void saveMhGradingAlarm(MhGradingAlarm mhGradingAlarm) {

        SimpleDateFormat simpleFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        mhGradingAlarm.setCreatTime(simpleFormatter.format(new Date()));
        mhGradingAlarm.setDeleteFlag("0");
        mhGradingAlarm.setTenentId(Context.getCurrentTenantId());
        mhGradingAlarm.setOrgCode(Context.getCurrentOrgCode());
        if (mhGradingAlarm.getId() != null){
            mhGradingAlarmMapper.updateById(mhGradingAlarm);
        } else {
            mhGradingAlarmMapper.insert(mhGradingAlarm);
        }
    }

    @Override
    public MhGradingAlarm getMhGradingAlarmById(Long id) {
        return mhGradingAlarmMapper.selectById(id);
    }

    @Override
    public MhGradingAlarmBean getMhGradingAlarmByOrgCode(String orgCode) {
        MhGradingAlarm mhGradingAlarm = mhGradingAlarmMapper.getMhGradingAlarmByOrgCode(orgCode);
        MhGradingAlarmBean mhGradingAlarmBean = new MhGradingAlarmBean();
        BeanUtils.copyProperties(mhGradingAlarm,mhGradingAlarmBean);
        String sdzrName = baseUserDao.getBaseUserNameById(Long.valueOf(mhGradingAlarm.getSdzr()));
        mhGradingAlarmBean.setSdzrName(sdzrName);
        String ddName = baseUserDao.getBaseUserNameById(Long.valueOf(mhGradingAlarm.getDd()));
        mhGradingAlarmBean.setDdName(ddName);
        String sdbmfzrName = baseUserDao.getBaseUserNameById(Long.valueOf(mhGradingAlarm.getSdbmfzr()));
        mhGradingAlarmBean.setSdbmfzrName(sdbmfzrName);
        String ahbName = baseUserDao.getBaseUserNameById(Long.valueOf(mhGradingAlarm.getAhb()));
        mhGradingAlarmBean.setAhbName(ahbName);
        String sdaqfzrName = baseUserDao.getBaseUserNameById(Long.valueOf(mhGradingAlarm.getSdaqfzr()));
        mhGradingAlarmBean.setSdaqfzrName(sdaqfzrName);
        String qyzyfzrName = baseUserDao.getBaseUserNameById(Long.valueOf(mhGradingAlarm.getQyzyfzr()));
        mhGradingAlarmBean.setQyzyfzrName(qyzyfzrName);
        String yhfzrName = baseUserDao.getBaseUserNameById(Long.valueOf(mhGradingAlarm.getYhfzr()));
        mhGradingAlarmBean.setYhfzrName(yhfzrName);
        return mhGradingAlarmBean;
    }

    @Override
    public void httpUrlGradingAlarmPush(MhGradingAlarmDto mhGradingAlarmDto, MhGradingAlarmBean mhGradingAlarmBean, int type){
        try {
            Map<String,Object> requestBody = new HashMap<>();
            // 构建消息体
            requestBody.put("alarmContent",mhGradingAlarmDto.getDetail()); // 报警内容
            requestBody.put("alarmTime",new Date());
            if (mhGradingAlarmBean!=null){
                BaseConfig baseConfig = null;
                if (type ==0){ // 隐患排查异常
                    baseConfig = baseConfigDao.findByTenentIdAndOrgCodeAndCode2(mhGradingAlarmDto.getTenentId(),mhGradingAlarmDto.getOrgCode(), BaseConfigCodes.YH_ProcessDefKey);
                } else if (type == 1){//重大危险源报警
                    baseConfig = baseConfigDao.findByTenentIdAndOrgCodeAndCode2(mhGradingAlarmDto.getTenentId(),mhGradingAlarmDto.getOrgCode(), BaseConfigCodes.ZD_ProcessDefKey);
                } else if (type == 2){//隐患整改报警
                    baseConfig = baseConfigDao.findByTenentIdAndOrgCodeAndCode2(mhGradingAlarmDto.getTenentId(),mhGradingAlarmDto.getOrgCode(), BaseConfigCodes.YH_ProcessDefKey);
                }
                requestBody.put("processDefKey",baseConfig.getValue());  //报警流程KYE
                String alarmLevel = BaseConfigCodes.MH_GRADING_ALARM_BLUE;  //属地主任、调度、属地部门负责人、安环部、属地和安全分管负责人、企业主要负责人
                requestBody.put("areaDirector",mhGradingAlarmBean.getSdzr()); //属地主任ids
                requestBody.put("$areaDirector",mhGradingAlarmBean.getSdzrName()); //属地主任名称
                BpDepart bpDepart=new BpDepart();
                Long dd=0L;
                Optional<BpDepart> bpDepartOptional = bpDepartDao.findById(mhGradingAlarmBean.getDd());
                if (bpDepartOptional.isPresent()) {
                    bpDepart = bpDepartOptional.get();
                    dd  = mhGradingAlarmBean.getDd();
                }
                requestBody.put("dispatcher",dd ); //调度人员ids
                requestBody.put("$dispatcher", bpDepart.getName()!=null?bpDepart.getName():"无"); //调度⼈员名称
                requestBody.put("areaDeptChief",mhGradingAlarmBean.getSdbmfzr()); //属地部门负责人ids
                requestBody.put("$areaDeptChief",mhGradingAlarmBean.getSdbmfzrName()); //属地部门负责人名称
                Optional<BpDepart> optional = bpDepartDao.findById(mhGradingAlarmBean.getAhb());
                String ahbDepartName="无";
                if (optional.isPresent()) {
                    BpDepart ahbDepart = optional.get();
                    ahbDepartName=ahbDepart.getName();
                }
                requestBody.put("safeEnvDept",mhGradingAlarmBean.getAhb()); //安环部ids
                requestBody.put("$safeEnvDept",ahbDepartName); //安环部名称
                requestBody.put("areaSafeChief",mhGradingAlarmBean.getSdaqfzr()); //属地安全分管负责人ids
                requestBody.put("$areaSafeChief",mhGradingAlarmBean.getSdaqfzrName()); //属地安全分管负责人名称
                requestBody.put("companyChief",mhGradingAlarmBean.getQyzyfzr()); //企业主要负责人ids
                requestBody.put("$companyChief",mhGradingAlarmBean.getQyzyfzrName()); //企业主要负责人名称

                if (StringUtils.isNotBlank(mhGradingAlarmDto.getLevelName()) && mhGradingAlarmDto.getLevelName().equals(BaseConfigCodes.MH_GRADING_ALARM_BLUE)){
                    alarmLevel = BaseConfigCodes.MH_GRADING_ALARM_YELLOW; //属地主任、调度、属地部门负责人、安环部
                }
                if (type ==0 || type==2){
                    requestBody.put("hiddenDangerChief",mhGradingAlarmBean.getYhfzr()); //隐患责任人ids
                    requestBody.put("$hiddenDangerChief",mhGradingAlarmBean.getYhfzrName()); //隐患责任人名称
                }
                requestBody.put("alarmLevel",alarmLevel); //报警等级
                log.info("请求参数："+new JSONObject(requestBody));
                Map<String,String> header = new HashMap<>();
                BaseConfig appId = baseConfigDao.findByTenentIdAndOrgCodeAndCode2(mhGradingAlarmDto.getTenentId(),mhGradingAlarmDto.getOrgCode(),BaseConfigCodes.APPID);
                header.put("app-id", appId.getValue());
                header.put("org-code",mhGradingAlarmBean.getOrgCode());
                header.put("tenant-id", String.valueOf(mhGradingAlarmDto.getTenentId()));
                BaseConfig signature = baseConfigDao.findByTenentIdAndOrgCodeAndCode2(mhGradingAlarmDto.getTenentId(),mhGradingAlarmDto.getOrgCode(),BaseConfigCodes.SIGNATURE);
                header.put("signature", signature.getValue());
                header.put("user-id", String.valueOf(9784)); //目前先写死
                header.put("user-name", "管理员"); //目前先写死
                BaseConfig workFlowIpAddress = baseConfigDao.findByTenentIdAndOrgCodeAndCode2(mhGradingAlarmDto.getTenentId(),mhGradingAlarmDto.getOrgCode(),BaseConfigCodes.WORKFLOW_IP_ADDRESS);
                 //增加默认
                if (workFlowIpAddress == null || StringUtils.isBlank(workFlowIpAddress.getValue())) {
                    workFlowIpAddress = new BaseConfig();
                    String workFlowIpAddressUrl = "http://127.0.0.1:8886";
                    workFlowIpAddress.setValue(workFlowIpAddressUrl);
                }
                BaseConfig outerNetWorkflowIpAddress = baseConfigDao.findByTenentIdAndOrgCodeAndCode2(mhGradingAlarmDto.getTenentId(),mhGradingAlarmDto.getOrgCode(),BaseConfigCodes.OUTER_NET_WORKFLOW_IP_ADDRESS);
                if (workFlowIpAddress != null && StringUtils.isNotBlank(workFlowIpAddress.getValue())){
                    String workFlowIpAddressUrl = workFlowIpAddress.getValue();
                    String substring1 = workFlowIpAddressUrl.substring(workFlowIpAddressUrl.indexOf("/") + 2);
                    String substring2 = substring1.substring(0, substring1.indexOf(":"));
                    boolean ping = ping(substring2);
                    if (ping){
                        String body = HttpRequest.post(workFlowIpAddressUrl +"/api/blade-workflow/process/startProcessByKey").headerMap(header, false).body(JSONUtil.toJsonStr(requestBody)).execute().body();
                        JSONObject jsonObject = JSONObject.parseObject(body);
                        log.info("接口返回："+jsonObject);
                        if (!String.valueOf(jsonObject.get("code")).equals(BaseConfigCodes.MH_GRADING_ALARM_CODE)){
                            if (type ==0){ // 隐患排查异常
                                inspectExceptionAlarmMesageMapper.setlevelNameById(mhGradingAlarmDto.getId(),alarmLevel); //蓝-黄-橙-红
                            } else if (type == 1){//重大危险源报警
                                mhAlarmMessageDao.setlevelNameById(mhGradingAlarmDto.getId(),alarmLevel, LocalDateTime.now()); //蓝-黄-橙-红
                            } else if (type == 2){//隐患整改报警
                                workFlowTaskDao.setlevelNameById(mhGradingAlarmDto.getId(),alarmLevel, LocalDateTime.now()); //蓝-黄-橙-红
                            }
                        } else if (String.valueOf(jsonObject.get("code")).equals(BaseConfigCodes.MH_GRADING_ALARM_CODE)){
                            if (type ==0){ // 隐患排查异常
                                inspectExceptionAlarmMesageMapper.setlevelNameById(mhGradingAlarmDto.getId(),null); //蓝-黄-橙-红
                            } else if (type == 1){//重大危险源报警
                                mhAlarmMessageDao.setlevelNameById(mhGradingAlarmDto.getId(),null, LocalDateTime.now()); //蓝-黄-橙-红
                            } else if (type == 2){//隐患整改报警
                                workFlowTaskDao.setlevelNameById(mhGradingAlarmDto.getId(),null, LocalDateTime.now()); //蓝-黄-橙-红
                            }
                        }
                    } else if (outerNetWorkflowIpAddress != null && StringUtils.isNotBlank(outerNetWorkflowIpAddress.getValue())){
                        String outerNetWorkflowIpAddressUrl = outerNetWorkflowIpAddress.getValue();
                        String substring = outerNetWorkflowIpAddressUrl.substring(outerNetWorkflowIpAddressUrl.indexOf("/") + 2);
                        String substring3 = substring.substring(0, substring.indexOf(":"));
                        boolean ping3 = ping(substring3);
                        if (ping3){
                            String body = HttpRequest.post(outerNetWorkflowIpAddressUrl +"/api/blade-workflow/process/startProcessByKey").headerMap(header, false).body(JSONUtil.toJsonStr(requestBody)).execute().body();
                            JSONObject jsonObject = JSONObject.parseObject(body);
                            log.info("接口返回："+jsonObject);
                            if (!String.valueOf(jsonObject.get("code")).equals(BaseConfigCodes.MH_GRADING_ALARM_CODE)){
                                if (type ==0){ // 隐患排查异常
                                    inspectExceptionAlarmMesageMapper.setlevelNameById(mhGradingAlarmDto.getId(),alarmLevel); //蓝-黄-橙-红
                                } else if (type == 1){//重大危险源报警
                                    mhAlarmMessageDao.setlevelNameById(mhGradingAlarmDto.getId(),alarmLevel, LocalDateTime.now()); //蓝-黄-橙-红
                                } else if (type == 2){//隐患整改报警
                                    workFlowTaskDao.setlevelNameById(mhGradingAlarmDto.getId(),alarmLevel, LocalDateTime.now()); //蓝-黄-橙-红
                                }
                            } else if (String.valueOf(jsonObject.get("code")).equals(BaseConfigCodes.MH_GRADING_ALARM_CODE)){
                                if (type ==0){ // 隐患排查异常
                                    inspectExceptionAlarmMesageMapper.setlevelNameById(mhGradingAlarmDto.getId(),null); //蓝-黄-橙-红
                                } else if (type == 1){//重大危险源报警
                                    mhAlarmMessageDao.setlevelNameById(mhGradingAlarmDto.getId(),null, LocalDateTime.now()); //蓝-黄-橙-红
                                } else if (type == 2){//隐患整改报警
                                    workFlowTaskDao.setlevelNameById(mhGradingAlarmDto.getId(),null, LocalDateTime.now()); //蓝-黄-橙-红
                                }
                            }
                        }else {
                            log.info("接口地址超时,请稍后再试");
                        }
                    } else {
                        log.info("外网接口地址未配置,请前往配置");
                    }
                } else if (outerNetWorkflowIpAddress != null && !"".equals(outerNetWorkflowIpAddress.getValue()) && outerNetWorkflowIpAddress.getValue() != null){
                    String outerNetWorkflowIpAddressUrl = outerNetWorkflowIpAddress.getValue();
                    String body = HttpRequest.post(outerNetWorkflowIpAddressUrl +"/api/blade-workflow/process/startProcessByKey").headerMap(header, false).body(JSONUtil.toJsonStr(requestBody)).execute().body();
                    JSONObject jsonObject = JSONObject.parseObject(body);
                    log.info("接口返回："+jsonObject);
                    if (!String.valueOf(jsonObject.get("code")).equals(BaseConfigCodes.MH_GRADING_ALARM_CODE)){
                        if (type ==0){ // 隐患排查异常
                            inspectExceptionAlarmMesageMapper.setlevelNameById(mhGradingAlarmDto.getId(),alarmLevel); //蓝-黄-橙-红
                        } else if (type == 1){//重大危险源报警
                            mhAlarmMessageDao.setlevelNameById(mhGradingAlarmDto.getId(),alarmLevel, LocalDateTime.now()); //蓝-黄-橙-红
                        } else if (type == 2){//隐患整改报警
                            workFlowTaskDao.setlevelNameById(mhGradingAlarmDto.getId(),alarmLevel, LocalDateTime.now()); //蓝-黄-橙-红
                        }
                    } else if (String.valueOf(jsonObject.get("code")).equals(BaseConfigCodes.MH_GRADING_ALARM_CODE)){
                        if (type ==0){ // 隐患排查异常
                            inspectExceptionAlarmMesageMapper.setlevelNameById(mhGradingAlarmDto.getId(),null); //蓝-黄-橙-红
                        } else if (type == 1){//重大危险源报警
                            mhAlarmMessageDao.setlevelNameById(mhGradingAlarmDto.getId(),null, LocalDateTime.now()); //蓝-黄-橙-红
                        } else if (type == 2){//隐患整改报警
                            workFlowTaskDao.setlevelNameById(mhGradingAlarmDto.getId(),null, LocalDateTime.now()); //蓝-黄-橙-红
                        }
                    }
                } else {
                    log.info("接口地址未配置,请前往配置");
                }
            }
        } catch (Exception e) {
            log.error("请求异常:"+e.getMessage());
            throw new RuntimeException(e);
        }
    }
    @Override
    public String httpUrlGradingAlarmPush(MhGradingAlarmDto mhGradingAlarmDto){
        String data = null;
        try {
            Map<String,Object> requestBody = new HashMap<>();
            // 构建消息体
            requestBody.put("alarmContent",mhGradingAlarmDto.getAlarmContent()); // 报警内容
            requestBody.put("alarmTime", DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
            requestBody.put("alarmValue",mhGradingAlarmDto.getAlarmValue());
            requestBody.put("monitoringPointName",mhGradingAlarmDto.getMonitoringPointName());
            BaseConfig baseConfig = baseConfigDao.findByTenentIdAndOrgCodeAndCode2(mhGradingAlarmDto.getTenentId(),mhGradingAlarmDto.getOrgCode(), BaseConfigCodes.ZD_ProcessDefKeyNew);
            requestBody.put("processDefKey",baseConfig.getValue());  //报警流程KYE
            requestBody.put("pointDept",mhGradingAlarmDto.getPointDept()); //设备部门ID
            requestBody.put("$pointDept",bpDepartDao.getNameById(mhGradingAlarmDto.getPointDept())); //设备部门名称

            requestBody.put("alarmLevel",mhGradingAlarmDto.getAlarmLevel()); //报警等级
            log.info("请求参数："+new JSONObject(requestBody));
            Map<String,String> header = new HashMap<>();
            BaseConfig appId = baseConfigDao.findByTenentIdAndOrgCodeAndCode2(mhGradingAlarmDto.getTenentId(),mhGradingAlarmDto.getOrgCode(),BaseConfigCodes.APPID);
            header.put("app-id", appId.getValue());
            header.put("org-code",mhGradingAlarmDto.getOrgCode());
            header.put("tenant-id", String.valueOf(mhGradingAlarmDto.getTenentId()));
            BaseConfig signature = baseConfigDao.findByTenentIdAndOrgCodeAndCode2(mhGradingAlarmDto.getTenentId(),mhGradingAlarmDto.getOrgCode(),BaseConfigCodes.SIGNATURE);
            header.put("signature", signature.getValue());
            header.put("user-id", String.valueOf(9784)); //目前先写死
            header.put("user-name", "管理员"); //目前先写死
            BaseConfig workFlowIpAddress = baseConfigDao.findByTenentIdAndOrgCodeAndCode2(mhGradingAlarmDto.getTenentId(),mhGradingAlarmDto.getOrgCode(),BaseConfigCodes.WORKFLOW_IP_ADDRESS);
            //增加默认
            if (workFlowIpAddress == null || StringUtils.isBlank(workFlowIpAddress.getValue())) {
                workFlowIpAddress = new BaseConfig();
                String workFlowIpAddressUrl = "http://127.0.0.1:8886";
                workFlowIpAddress.setValue(workFlowIpAddressUrl);
            }
            BaseConfig outerNetWorkflowIpAddress = baseConfigDao.findByTenentIdAndOrgCodeAndCode2(mhGradingAlarmDto.getTenentId(),mhGradingAlarmDto.getOrgCode(),BaseConfigCodes.OUTER_NET_WORKFLOW_IP_ADDRESS);
            if (workFlowIpAddress != null && StringUtils.isNotBlank(workFlowIpAddress.getValue())){
                String workFlowIpAddressUrl = workFlowIpAddress.getValue();
                String substring1 = workFlowIpAddressUrl.substring(workFlowIpAddressUrl.indexOf("/") + 2);
                String substring2 = substring1.substring(0, substring1.indexOf(":"));
                boolean ping = ping(substring2);
                if (ping){
                    String body = HttpRequest.post(workFlowIpAddressUrl +"/api/blade-workflow/process/startProcessByKey").headerMap(header, false).body(JSONUtil.toJsonStr(requestBody)).execute().body();
                    JSONObject jsonObject = JSONObject.parseObject(body);
                    log.info("接口返回："+jsonObject);
                    if (!String.valueOf(jsonObject.get("code")).equals(BaseConfigCodes.MH_GRADING_ALARM_CODE)){
                        mhAlarmMessageDao.setlevelNameById(mhGradingAlarmDto.getId(),mhGradingAlarmDto.getAlarmLevel(), LocalDateTime.now()); //蓝-黄-橙-红
                    } else if (String.valueOf(jsonObject.get("code")).equals(BaseConfigCodes.MH_GRADING_ALARM_CODE)){
                        mhAlarmMessageDao.setlevelNameById(mhGradingAlarmDto.getId(),null, LocalDateTime.now()); //蓝-黄-橙-红
                    }
                    data = String.valueOf(jsonObject.get("data"));
                } else if (outerNetWorkflowIpAddress != null && StringUtils.isNotBlank(outerNetWorkflowIpAddress.getValue())){
                    String outerNetWorkflowIpAddressUrl = outerNetWorkflowIpAddress.getValue();
                    String substring = outerNetWorkflowIpAddressUrl.substring(outerNetWorkflowIpAddressUrl.indexOf("/") + 2);
                    String substring3 = substring.substring(0, substring.indexOf(":"));
                    boolean ping3 = ping(substring3);
                    if (ping3){
                        String body = HttpRequest.post(outerNetWorkflowIpAddressUrl +"/api/blade-workflow/process/startProcessByKey").headerMap(header, false).body(JSONUtil.toJsonStr(requestBody)).execute().body();
                        JSONObject jsonObject = JSONObject.parseObject(body);
                        log.info("接口返回："+jsonObject);
                        if (!String.valueOf(jsonObject.get("code")).equals(BaseConfigCodes.MH_GRADING_ALARM_CODE)){
                            mhAlarmMessageDao.setlevelNameById(mhGradingAlarmDto.getId(),mhGradingAlarmDto.getAlarmLevel(), LocalDateTime.now()); //蓝-黄-橙-红
                        } else if (String.valueOf(jsonObject.get("code")).equals(BaseConfigCodes.MH_GRADING_ALARM_CODE)){
                            mhAlarmMessageDao.setlevelNameById(mhGradingAlarmDto.getId(),null, LocalDateTime.now()); //蓝-黄-橙-红
                        }
                        data = String.valueOf(jsonObject.get("data"));
                    }else {
                        log.info("接口地址超时,请稍后再试");
                    }
                } else {
                    log.info("外网接口地址未配置,请前往配置");
                }
            } else if (outerNetWorkflowIpAddress != null && !"".equals(outerNetWorkflowIpAddress.getValue()) && outerNetWorkflowIpAddress.getValue() != null){
                String outerNetWorkflowIpAddressUrl = outerNetWorkflowIpAddress.getValue();
                String body = HttpRequest.post(outerNetWorkflowIpAddressUrl +"/api/blade-workflow/process/startProcessByKey").headerMap(header, false).body(JSONUtil.toJsonStr(requestBody)).execute().body();
                JSONObject jsonObject = JSONObject.parseObject(body);
                log.info("接口返回："+jsonObject);
                if (!String.valueOf(jsonObject.get("code")).equals(BaseConfigCodes.MH_GRADING_ALARM_CODE)){
                    mhAlarmMessageDao.setlevelNameById(mhGradingAlarmDto.getId(),mhGradingAlarmDto.getAlarmLevel(), LocalDateTime.now()); //蓝-黄-橙-红
                } else if (String.valueOf(jsonObject.get("code")).equals(BaseConfigCodes.MH_GRADING_ALARM_CODE)){
                    mhAlarmMessageDao.setlevelNameById(mhGradingAlarmDto.getId(),null, LocalDateTime.now()); //蓝-黄-橙-红
                }
                data = String.valueOf(jsonObject.get("data"));
            } else {
                log.info("接口地址未配置,请前往配置");
            }
        } catch (Exception e) {
            log.error("请求异常:"+e.getMessage());
            throw new RuntimeException(e);
        }
        return data;
    }

    public static boolean ping(String ipAddress) throws Exception {
        int timeOut = 3000;  //超时应该在3钞以上
        boolean status = InetAddress.getByName(ipAddress).isReachable(timeOut);
        // 当返回值是true时，说明host是可用的，false则不可。
        return status;
    }
}
